var OrderModule;
(function (OrderModule) {
    //订单操作管理类
    var Order = (function () {
        function Order(oDialog) {
            this.data = {};
            this.onlinePaymentUrl = ''; //在线支付
            //this.cashOnDeliveryUrl = ''; //货到付款
            this.confirmReceiveUrl = ''; //确认收货
            this.cancelOrderUrl = ''; //取消订单
            this.deleteOrderUrl = ''; //删除订单
            this.commentUrl='';
            this.refundUrl='';
            this.refundDetailUrl='';
            this.dialog = oDialog;
        }

        /**
         * 在线支付
         * @param context
         * @param url
         */
        Order.prototype.onlinePayment = function (order) {
            location.href=this.onlinePaymentUrl+"?orderNo="+order.orderNo;
        };

        /**
         * 货到付款
         * @param context
         * @param url
         */
        Order.prototype.cashOnDelivery = function(context, order){
            console.info('货到付款');
        };

        /**
         * 确认收货
         * @param context
         * @param url
         * @param data
         */
        Order.prototype.confirmReceive = function(context, order){
            var _this = this;
            var nDialog = this.dialog.confirm("你确定确认收货?",function(){
                ajax({
                    url: _this.confirmReceiveUrl,
                    data: {orderNo: order.orderNo},
                    showError: true,
                    cache: false,
                    success: function(data){
                        if(data.type == 'success'){
                            _this.orderEvent.confirmReceive(context, order);
                        }
                        _this.dialog.prompt(data.content, 2000);
                    }
                })
             },function(){
                nDialog.close();
            },"确认收货");
        };

        /**
         * 评价
         * @param context
         * @param data
         */
        Order.prototype.comment = function(context, order){
            location.href = this.commentUrl + "?orderNo=" + order.orderNo;
        };

        /**
         * 取消订单
         * @param context
         * @param url
         * @param data
         */
        Order.prototype.cancelOrder = function(context, order){
            var _this = this;
            var nDialog = this.dialog.confirm("你确定取消订单?",
                function(){
                    ajax({
                        url: _this.cancelOrderUrl,
                        data: {orderNo: order.orderNo},
                        showError: true,
                        cache: false,
                        success: function(data){
                            if(data.type == 'success'){
                                _this.orderEvent.cancel(context, order);
                            }
                            _this.dialog.prompt(data.content, 2000);
                        }
                    });
                },
                function(){
                    nDialog.close();
                },
                "取消订单"
            );
        };

        /**
         * 删除订单
         */
        Order.prototype.deleteOrder = function(context, order){
            var _this = this;
            var nDialog = this.dialog.confirm("你确定删除订单?",function(){
                ajax({
                    url: _this.deleteOrderUrl,
                    data: {orderNo: order.orderNo},
                    showError: true,
                    cache: false,
                    success: function(data){
                        if(data.type == 'success'){
                            _this.orderEvent.del(context);
                        }
                        _this.dialog.prompt(data.content, 2000);
                    }
                });
            },function(){
                nDialog.close();
            },"删除订单");

        };

        /**
         * 申请退款
         */
        Order.prototype.refund = function(context, order){
            location.href = this.refundUrl +"?orderNo=" + order.orderNo;
        };

        /**
         *退款详情
         */
        Order.prototype.refundDetail = function(context, order){
            location.href = this.refundDetailUrl +"?orderNo=" + order.orderNo;
        };
        return Order;
    })();
    OrderModule.Order = Order;
})(OrderModule || (OrderModule = {}));

